package master.ghrm.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Version;

@Entity
@NamedQueries( {
		@NamedQuery(name = PDPReminder.QUERY_BY_EVALUATION, query = "from PDPReminder pdp where pdp.id.evaluation = :evaluation"),
		@NamedQuery(name = PDPReminder.QUERY_BY_CATEGORY, query = "from PDPReminder pdp where pdp.id.category = :category order by pdp.id.evaluation.evalDate"),
		@NamedQuery(name = PDPReminder.QUERY_BY_PROFILE_AND_EVALUATION, query = "from PDPReminder pdp where pdp.id.evaluation.evaluee = :profile and pdp.id.evaluation = :evaluation") })
public class PDPReminder extends AbstractBaseEntity {

	private static final long serialVersionUID = 1L;

	/**
	 * Name of the named query for finding PDP Reminders by category.
	 */
	public static final String QUERY_BY_CATEGORY = "PDPReminder.byCategory";

	/**
	 * Name of the named query for finding PDP Reminders by assessment.
	 */
	public static final String QUERY_BY_EVALUATION = "PDPReminder.byEvaluation";

	/**
	 * Name of the named query for finding PDP Reminders by profile and evaluation.
	 */
	public static final String QUERY_BY_PROFILE_AND_EVALUATION = "PDPReminder.byProfileAndEvaluation";
	/**
	 * Maximum length for goal fields.
	 */
	public static final int LENGTH_GOAL = 1000;

	/**
	 * Composite ID class for {@link PDPReminder}.
	 */
	@Embeddable
	public static class Id implements Serializable {

		private static final long serialVersionUID = 1L;

		@ManyToOne
		@JoinColumn(name = "category_id", nullable = false)
		private EvalCategory category;

		@ManyToOne
		@JoinColumn(name = "evaluation_id", nullable = false)
		private Evaluation evaluation;

		/**
		 * Full (and only) constructor.
		 * 
		 * @param aCategory question category.
		 * @param anEvaluation evaluation where the PDP Reminder was filled in.
		 */
		public Id(EvalCategory aCategory, Evaluation anEvaluation) {
			super();
			this.category = aCategory;
			this.evaluation = anEvaluation;
		}

		/**
		 * Default constructor, for persistence use only.
		 */
		Id() {
			super();
		}

		/**
		 * @return the category
		 */
		public EvalCategory getCategory() {
			return category;
		}

		/**
		 * @param aCategory the category to set
		 */
		void setCategory(EvalCategory aCategory) {
			this.category = aCategory;
		}

		/**
		 * @return the evaluation
		 */
		public Evaluation getEvaluation() {
			return evaluation;
		}

		/**
		 * @param anEvaluation the evaluation to set
		 */
		void setEvaluation(Evaluation anEvaluation) {
			this.evaluation = anEvaluation;
		}

		/**
		 * Eclipse generated.
		 * 
		 * @see java.lang.Object#hashCode()
		 */
		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + ((category == null) ? 0 : category.hashCode());
			result = prime * result + ((evaluation == null) ? 0 : evaluation.hashCode());
			return result;
		}

		/**
		 * Eclipse generated.
		 * 
		 * @see java.lang.Object#equals(java.lang.Object)
		 */
		@Override
		public boolean equals(Object obj) {
			if (this == obj) {
				return true;
			}
			if (obj == null) {
				return false;
			}
			if (getClass() != obj.getClass()) {
				return false;
			}
			final Id other = (Id) obj;
			if (category == null) {
				if (other.category != null) {
					return false;
				}
			} else if (!category.equals(other.category)) {
				return false;
			}
			if (evaluation == null) {
				if (other.evaluation != null) {
					return false;
				}
			} else if (!evaluation.equals(other.evaluation)) {
				return false;
			}
			return true;
		}
	}

	@EmbeddedId
	private Id id;

	@Column(name = "employee_short_term_goals", length = LENGTH_GOAL)
	private String employeeShortTermGoals;

	@Column(name = "employee_long_term_goals", length = LENGTH_GOAL)
	private String employeeLongTermGoals;

	@Column(name = "planned_actions", length = LENGTH_GOAL)
	private String plannedActions;

	@Version
	private Long version;

	/**
	 * Default constructor, for Persistence use only.
	 */
	PDPReminder() {
		super();
	}

	/**
	 * Full constructor.
	 * 
	 * @param category question category this reminder refers to.
	 * @param evaluation particular evaluation.
	 * @param anEmployeeShortTermGoals employee's short term goals.
	 * @param anEmployeeLongTermGoals employee's long term goals.
	 * @param anEmployeePlannedActions plannedActions.
	 */
	public PDPReminder(EvalCategory category, Evaluation evaluation, String anEmployeeShortTermGoals,
			String anEmployeeLongTermGoals, String anEmployeePlannedActions) {
		super();
		this.id = new Id(category, evaluation);
		this.employeeShortTermGoals = anEmployeeShortTermGoals;
		this.employeeLongTermGoals = anEmployeeLongTermGoals;
		this.plannedActions = anEmployeePlannedActions;
	}

	/**
	 * Minimal constructor for external instantiation.
	 * 
	 * @param category question category this reminder applies to.
	 * @param evaluation evaluation when the reminder was created.
	 */
	public PDPReminder(EvalCategory category, Evaluation evaluation) {
		super();
		this.id = new Id(category, evaluation);
	}

	/**
	 * @return the id
	 */
	public Id getId() {
		return id;
	}

	/**
	 * @param anId the id to set
	 */
	public void setId(Id anId) {
		this.id = anId;
	}

	/**
	 * @return the category
	 */
	public EvalCategory getCategory() {
		return id.getCategory();
	}

	/**
	 * @return the evaluation
	 */
	public Evaluation getEvaluation() {
		return id.getEvaluation();
	}

	/**
	 * @return the employee's short term goals
	 */
	public String getEmployeeShortTermGoals() {
		return employeeShortTermGoals;
	}

	/**
	 * @param anEmployeeShortTermGoals short term goals to set
	 */
	public void setEmployeeShortTermGoals(String anEmployeeShortTermGoals) {
		this.employeeShortTermGoals = anEmployeeShortTermGoals;
	}

	/**
	 * @return the employee's long term goals
	 */
	public String getEmployeeLongTermGoals() {
		return employeeLongTermGoals;
	}

	/**
	 * @param anEmployeeLongTermGoals long term goals to set
	 */
	public void setEmployeeLongTermGoals(String anEmployeeLongTermGoals) {
		this.employeeLongTermGoals = anEmployeeLongTermGoals;
	}

	/**
	 * @return the employee's planned actions
	 */
	public String getPlannedActions() {
		return plannedActions;
	}

	/**
	 * @param anEmployeeplannedActions planned actions to set
	 */
	public void setPlannedActions(String anEmployeeplannedActions) {
		this.plannedActions = anEmployeeplannedActions;
	}

	/**
	 * Persistent entity version, for persistence use only.
	 * 
	 * @return the entity version
	 */
	Long getVersion() {
		return version;
	}

	/**
	 * Persistent entity version, for persistence use only.
	 * 
	 * @param aVersion the entity version to set.
	 */
	void setVersion(Long aVersion) {
		this.version = aVersion;
	}

	/**
	 * All attributes are key attributes, none will be excluded.
	 * 
	 * @see com.levi9.hrm.model.base.AbstractBaseEntity#getExcludedAttributes()
	 */
	@Override
	protected String[] getExcludedAttributes() {
		return null;
	}
}
